package com.tianlang.web.member.controller;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.tianlang.domain.pojo.Account;
import com.tianlang.freemarker.tag.AuthorityTag;
import com.tianlang.service.IBaseManager;

/**
 * 
 * @author mcp
 *
 */
@Controller
@Scope("prototype")
@RequestMapping("/login")
public class LoginController {

	@Autowired
	IBaseManager baseManager;
	@Autowired
	AuthorityTag authorityTag;
	@Autowired
	SessionFactory sessionFactory;

	@RequestMapping(value = "")
	public String index(String uid, Model model) {
		Session session1 = sessionFactory.openSession();
		Transaction tr1 = session1.beginTransaction();
		// 加载一个OID为1的对象
		Account customer1 = session1.get(Account.class, "402882f35e7f14e5015e7f1510d50000");
		System.out.println("session1" + customer1.getUserName());
		tr1.commit();
		session1.close();

		// 加载同样OID为2的对象
		Session session2 = sessionFactory.openSession();
		Transaction tr2 = session2.beginTransaction();
		Account customer2 = session2.get(Account.class, "402882f35e7f14e5015e7f1510d50000");
		System.out.println("session2" + customer2.getUserName());
		tr2.commit();
		session2.close();
		return "login";
	}
}
